package com.hl.testdb.db;

import android.content.ContentValues;
import android.database.Cursor;

import com.hl.testdb.db.bean.Person;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/19 0019.
 */

public final class DBUtils {
    public static void insert(ContentValues values)
    {
        DBOperator operator = new DBOperator();
        operator.insert(values);
        operator.close();
    }

    public static List<Person> getAllPersons()
    {
        DBOperator operator = new DBOperator();
        Cursor cursor = operator.selectAll();
        if (cursor == null) return null;
        List<Person> persons = new ArrayList<>();
        Person person;
        while (cursor.moveToNext())
        {
            person = new Person();
            person.setService_id(cursor.getInt(cursor.getColumnIndex("service_id")));
            person.setName(cursor.getString(cursor.getColumnIndex("name")));
            person.setAge(cursor.getInt(cursor.getColumnIndex("age")));
            persons.add(person);
        }
        cursor.close();
        operator.close();


        return persons;
    }


}
